﻿Imports System.Data.OleDb

Public Class DeleteComment
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim prevPage As String = String.Empty
        If Request.Params("ID") = "" Then Response.Redirect("Profile.aspx?User=" & User.Identity.Name)

        If (Not IsPostBack) Then
            prevPage = Request.UrlReferrer.ToString()
        End If

        'Parse the URL to get the value in the Querystring
        Dim getQueryString As String = Request.QueryString("ID")

        'Delete the Comment Relationship
        Dim delCommentDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("recipeConnectionString").ConnectionString)
        Dim delCommentSqlString = "DELETE from COMMENT where COMM_ID=@f1 "
        Dim delCommentCommand As OleDbCommand = New OleDbCommand(delCommentSqlString, delCommentDbConn)
        delCommentCommand.CommandType = CommandType.Text
        delCommentCommand.Parameters.AddWithValue("@f1", getQueryString)
        delCommentDbConn.Open()
        delCommentCommand.ExecuteNonQuery()
        delCommentCommand.Dispose()
        delCommentDbConn.Close()
        delCommentDbConn.Dispose()

        Response.Redirect(prevPage)

    End Sub

End Class